Page({
  data: {
    list: [],
    name: "",
    Source: [
      {
        "ListItemId": 1,
        "ListItemName": "小区开发"
      },
      {
        "ListItemId": 2,
        "ListItemName": "门市零售"
      },
      {
        "ListItemId": 3,
        "ListItemName": "公司内部推荐"
      },
      {
        "ListItemId": 4,
        "ListItemName": "老客户介绍"
      },
      {
        "ListItemId": 5,
        "ListItemName": "渠道合作"
      },
      {
        "ListItemId": 6,
        "ListItemName": "线上引流"
      },
      {
        "ListItemId": 7,
        "ListItemName": "商务工程"
      }
    ],
    CustomerQuTypeId: [
      {
        "ListItemId": 22,
        "ListItemName": "分销客户"
      },
      {
        "ListItemId": 23,
        "ListItemName": "渠道客户"
      }
    ],

    CustomerTypeId: [
      {
        "ListItemId": 2,
        "ListItemName": "个人"
      },
      {
        "ListItemId": 3,
        "ListItemName": "代理商"
      },
      {
        "ListItemId": 4,
        "ListItemName": "合作伙伴"
      },
      {
        "ListItemId": 5,
        "ListItemName": "推广员"
      },
      {
        "ListItemId": 10,
        "ListItemName": "供货商"
      },
      {
        "ListItemId": 15,
        "ListItemName": "酷家乐客户"
      },
      {
        "ListItemId": 20,
        "ListItemName": "电话客户"
      },
      {
        "ListItemId": 21,
        "ListItemName": "网络客户"
      },
      {
        "ListItemId": 22,
        "ListItemName": "分销客户"
      },
      {
        "ListItemId": 23,
        "ListItemName": "加盟商"
      },
      {
        "ListItemId": 24,
        "ListItemName": "零售客户"
      },
      {
        "ListItemId": 25,
        "ListItemName": "样板房客户"
      },
      {
        "ListItemId": 26,
        "ListItemName": "工程客户"
      }
    ],
    ContactTypeId: [{
      "ListItemId": 1,
      "ListItemName": "电话"
    },
    {
      "ListItemId": 2,
      "ListItemName": "手机"
    },
    {
      "ListItemId": 3,
      "ListItemName": "微信"
    },
    {
      "ListItemId": 4,
      "ListItemName": "邮箱"
    },
    {
      "ListItemId": 5,
      "ListItemName": "QQ"
    }],
    Direction: [{
      "ListItemId": 1,
      "ListItemName": "客户主动联系"
    }, {
      "ListItemId": 2,
      "ListItemName": "我方主动联系"
    }],
  },
  onLoad(e) {
    console.log(e)
    var _this = this
    if (e.num) {
      getApp().req({
        url: "/customer/getlistdata/" + e.num,
        cb(res) {
          console.log(res)
          _this.setData({
            list: res.data[0].ListItems.Items
          })
        }
      })
    } else {
      this.setData({
        list: this.data[e.name]
      })
    }
    this.setData({
      name: e.name
    })
  },
  radioChange(e) {
    console.log(e)
    var proview = getCurrentPages()[getCurrentPages().length - 2]
    var newlist = proview.data.info
    var keyname = this.data.name
    console.log(this.data.name)
    if (keyname.substr(-2) == "Id") {
      keyname = keyname.substr(0, keyname.length - 2)
    }
    var kerword = ''
    for (const i in this.data.list) {
      if (this.data.list[i].ListItemId == e.detail.value) {
        kerword = this.data.list[i].ListItemName;
        break;
      }
    }
    console.log(kerword)
    if (this.data.name == "CustomerTypeId") {
      newlist.Customer[this.data.name] = e.detail.value
      newlist[this.data.name] = e.detail.value
    }else if(this.data.name == 'FromSource'){
      console.log(1);
      
      newlist[this.data.name] = e.detail.value
      newlist.From.ListItemName = kerword
    }else if(this.data.name == 'CustomerQuTypeId'){
      newlist.CustomerTypeId = e.detail.value
      newlist["CustomerTypeName"] = kerword;
    }else if(this.data.name == 'cIntention'){
      newlist.Customer.Intention = e.detail.value
      newlist[keyname + "Name"] = kerword;
    }else if(this.data.name == 'qIntention'){
      newlist.Intention = e.detail.value
      newlist.IntentionName.ListItemName = kerword;
    }else {
      newlist[this.data.name] = e.detail.value
      newlist[keyname + "Name"] = kerword;
    }
      // if(this.data.name == "Intention"){
      //   newlist.Customer[this.data.name] = e.detail.value
      // }else{
      //   newlist[this.data.name] = e.detail.value
      // }
      // if (this.data.name == 'Intention') {
      //   newlist[this.data.name] = e.detail.value
      // } else {
      //   for (const i in this.data.list) {
      //     if (this.data.list[i].ListItemId == e.detail.value) {
      //       newlist[keyname + "Name"] = this.data.list[i].ListItemName;
      //       break;
      //     }
      //   }
      // }


    //    if (this.data.name == 'FromSource') {
    //     newlist[this.data.name] = e.detail.value
    //   } else {
    //     for (const i in this.data.list) {
    //       if (this.data.list[i].ListItemId == e.detail.value) {
    //         newlist[keyname + "Name"] = this.data.list[i].ListItemName;
    //         break;
    //       }
    //     }
    //   }

    //   if (this.data.name == 'CustomerQuTypeId') {
    //     newlist[this.data.name] = e.detail.value
    //   } else {
    //     for (const i in this.data.list) {
    //       if (this.data.list[i].ListItemId == e.detail.value) {
    //         newlist[keyname + "Name"] = this.data.list[i].ListItemName;
    //         break;
    //       }
    //     }
    //   }
    // }

    // if (this.data.name == 'Intention') {
    //     newlist[this.data.name] = e.detail.value
    //   } else {
    //     for (const i in this.data.list) {
    //       if (this.data.list[i].ListItemId == e.detail.value) {
    //         newlist[keyname + "Name"] = this.data.list[i].ListItemName;
    //         break;
    //       }
    //     }
    //   }
    // for (const i in this.data.list) {
    //   if (this.data.list[i].ListItemId == e.detail.value) {
    //     newlist[keyname + "Name"] = this.data.list[i].ListItemName;
    //     break;
    //   }
    // }




// delete newlist.CustomerTypeId

 
    // if(newlist.CustomerId !==0) {
    // newlist.CustomerQuTypeId =newlist.CustomerTypeId
    //   console.log(1)

    // } else {
    //   console.log(2)
    // console.log(newlist.CustomerTypeId )
    // console.log(newlist.CustomerQuTypeId  )

    // }

    proview.setData({

      info: newlist
      

    })
    dd.navigateBack()
    console.log(proview);





  }
});
